package com.asset.dispoal.business.bsEvidenceRecognition.service.commom;

import com.asset.dispoal.business.bsEvidenceRecognition.domain.db.mapper.BusinessDataManageMapper;
import com.asset.dispoal.business.bsEvidenceRecognition.dto.EvidenceMatchHistoryFileRequest;
import com.asset.dispoal.business.bsEvidenceRecognition.dto.EvidenceMatchHistoryFileResponse;
import com.asset.dispoal.commom.page.PagingQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

@Component
@Slf4j
public class QueryEvidenceMatchHistoryFileCommand implements BaseCommand<EvidenceMatchHistoryFileRequest, Result<PageVO<EvidenceMatchHistoryFileResponse>>> {


    @Autowired
    BusinessDataManageMapper businessDataManageMapper;


    @Override
    public Result<PageVO<EvidenceMatchHistoryFileResponse>> execute(EvidenceMatchHistoryFileRequest evidenceMatchHistoryFileRequest) {
        int count = businessDataManageMapper.queryCountEvidenceHistoryFile(evidenceMatchHistoryFileRequest);
        Page<EvidenceMatchHistoryFileRequest> page = PagingQuery.getPage(count, evidenceMatchHistoryFileRequest);
        PageVO<EvidenceMatchHistoryFileResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (null != page) {
            List<EvidenceMatchHistoryFileResponse> agreementDataResponses = businessDataManageMapper.queryEvidenceHistoryFile(page);
            pageVO.setResult(agreementDataResponses);
        }
        return Result.ok(pageVO);
    }
}
